﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MappingWorkspace
{

    public static partial class MappingClassTestSample
    {

        /// <summary>
        /// Maps the specified source.
        ///  </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static MappingTest.Destination1.ClassTest Map(this MappingTest.Sources.ClassTest source)
        {           
            return Map(source, null);
        }

        public static MappingTest.Destination1.ClassTest Map(this MappingTest.Sources.ClassTest source, MappingTest.Destination1.ClassTest destination)
        {

            if (source == null)
                return null;

            if (destination == null)
                destination = new MappingTest.Destination1.ClassTest();

            destination.Property1 = source.Property1;
            destination.Property2 = source.Property2;

            destination.Property3 = source.Property3.Map();

            return destination;
        }

    }


    public static partial class MappingClassTest2Sample
    {


        /// <summary>
        /// Maps the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static MappingTest.Destination1.ClassTest2 Map(this MappingTest.Sources.ClassTest2 source)
        {            
            return Map(source, null);
        }


        // Methode débrailllé pour laisser à l'utilisateur le loisir d'écrire un truc à lui.
        //public static MappingTest.Destination1.ClassTest2 Map(this MappingTest.Sources.ClassTest2 source, MappingTest.Destination1.ClassTest2 destination)
        //{

        //    if (source == null)
        //        return null;

        //    if (destination == null)
        //        destination = new MappingTest.Destination1.ClassTest2();

        //    destination.Property1 = source.Property1;
        //    destination.Property2 = source.Property2;

        //    destination.Property3 = source.Property3.MapCollection();

        //    return destination;
        //}

    }

    public static partial class MappingClassTest3Sample
    {

        /// <summary>
        /// Maps the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static IEnumerable<MappingTest.Destination1.ClassTest3> MapCollection(this IEnumerable<MappingTest.Sources.ClassTest3> source)
        {            
            return MapCollection(source, null);
        }


        public static IEnumerable<MappingTest.Destination1.ClassTest3> MapCollection(this IEnumerable<MappingTest.Sources.ClassTest3> source, IEnumerable<MappingTest.Destination1.ClassTest3> destination)
        {

            if (source == null)
                return null;

            if (destination == null)
                destination = new List<MappingTest.Destination1.ClassTest3>();

            List<MappingTest.Destination1.ClassTest3> 
                d = (destination as List<MappingTest.Destination1.ClassTest3>);

            foreach (MappingTest.Sources.ClassTest3 item in source)
                d.Add(item.Map());

            return destination;

        }

        /// <summary>
        /// Maps the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static MappingTest.Destination1.ClassTest3 Map(this MappingTest.Sources.ClassTest3 source)
        {            
            return Map(source, null);
        }

        public static MappingTest.Destination1.ClassTest3 Map(this MappingTest.Sources.ClassTest3 source, MappingTest.Destination1.ClassTest3 destination)
        {

            if (source == null)
                return null;

            if (destination == null)
                destination  = new MappingTest.Destination1.ClassTest3();

            destination.Property1 = source.Property1;
            return destination;

        }

    }

}
